package ui.activity.wallet.presenter;


import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import base.BaseBiz;
import coom.Constants;
import ui.activity.wallet.biz.RewardsDetailsOtherBiz;
import ui.activity.wallet.contract.RewardsDetailsOtherContract;
import ui.model.RewardsTrainTopBean;

/**
 * Created by chenjian on 19/2/26
 */

public class RewardsDetailsOtherPresenter implements RewardsDetailsOtherContract.Presenter {

    RewardsDetailsOtherContract.View view;
    RewardsDetailsOtherBiz biz;
    List<RewardsTrainTopBean.RecordsBean> list = new ArrayList<>();
    private int pageIndex = 1;

    @Inject
    public RewardsDetailsOtherPresenter(RewardsDetailsOtherContract.View view) {
        this.view = view;
    }


    @Override
    public void setBiz(BaseBiz biz) {
        this.biz = (RewardsDetailsOtherBiz) biz;
    }


    @Override
    public void getListInfo(final boolean isRefresh, int type, long time, int year, int month) {
        if (isRefresh) {
            list.clear();
            pageIndex = 1;
        }
        view.loading(true);
        biz.getListInfo(type, pageIndex, Constants.PAGESIZE, year, month, new BaseBiz.Callback<RewardsTrainTopBean>() {
            @Override
            public void onSuccess(RewardsTrainTopBean info) {
                list.addAll(info.getRecords());
                view.upDateUI(list);
                pageIndex++;
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
                view.hasLoadMore(Constants.PAGESIZE == info.getRecords().size());
                view.loading(false);
            }

            @Override
            public void onFailure(RewardsTrainTopBean info) {
                view.loading(false);
                if (isRefresh) {
                    view.refreshComplete();
                } else {
                    view.loadMoreComplete();
                }
            }
        });
    }

}
